package com.lunchEveryDay.controller;

import com.lunchEveryDay.entity.User;
import com.lunchEveryDay.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by Admin on 2015/7/20.
 */
@Controller
public class AuthController {
	@Resource
	private UserService userService;
	@RequestMapping(value = "login",method = RequestMethod.GET)
	public ModelAndView login() {
		return new ModelAndView("login");
	}
	@RequestMapping(value = "login",method = RequestMethod.POST)
	public ModelAndView login(User u) {
		User user = userService.getUserByUsername(u.getUsername());
		if (null==user)
			;
		else if (user.getPassword().equals(u.getPassword()))
			return new ModelAndView("redirect:index");
		return new ModelAndView("redirect:/login");
	}
}
